package com.allbluefish.learn.model;

import java.util.ArrayList;
import java.util.List;

public class Plate {

	List<Object> eggs = new ArrayList<Object>();

	public synchronized Object getEgg() {
		while (this.eggs.size() == 0) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		Object egg = this.eggs.get(0);
		this.eggs.clear();// 清空盘子
		notify();// 唤醒阻塞队列的某线程到就绪队列
		System.out.println("拿到鸡蛋");
		return egg;
	}

	public synchronized void putEgg(Object egg) {
		while (this.eggs.size() > 0) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.eggs.add(egg);// 往盘子里放鸡蛋
		notify();// 唤醒阻塞队列的某线程到就绪队列
		System.out.println("放入鸡蛋");

	}

}